package com.swsc.xapp.utils;

import android.text.TextUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CodeUtils {
    public static String generateBatchNo(int organNo, String patrolTimeStr, int num){
        Date patrolTime = null;
        // 20230328 100302001 01 01
        if(TextUtils.isEmpty(patrolTimeStr)){
            patrolTime = new Date();
        }else {
            patrolTimeStr = patrolTimeStr.substring(0, 10);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                patrolTime = sdf.parse(patrolTimeStr);
            } catch (ParseException e) {
                android.util.Log.e("时间转换", e.getMessage());
            }
        }
        return generateBatchNo(organNo, patrolTime, num);
    }
    public static String generateBatchNo(int organNo, Date patrolTime, int num){
        // 20230328 100302001 01 01
        if(null == patrolTime){
            patrolTime = new Date();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        return sdf.format(patrolTime).concat(String.format("%09d", organNo)).concat("01").concat(String.format("%02d", num));
    }
}
